*****************************************************************************
*    Table Additional Context Spoon & Kluever's replication data	        *
*																			*			
* Author: 			Valentina Gonzalez Rostani		        				*
* Contact: 			mag384@pitt.edu              							*
* Date: 			August 9 2024   										*
* Version:			Stata 17 												*                                                                          
*																			*
*****************************************************************************
/*
This do-file:
- Creates Table A10 using data from Spoon & Kluever's replication data (EJPR, 2019). 

Input:
- Data\SpoonKluever_2019_EJPR_PartyConvergence.dta

Output:
- Table A10: Switching in Germany from mainstream to non-mainstream parties 2002-2013

*/

*Defining Directory
cd "C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication"

*##########################################
* Load data
*##########################################
{
*Calling the data
use "Data\SpoonKluever_2019_EJPR_PartyConvergence.dta", clear 
}
*******************************************************************************
* Preparing variables
*******************************************************************************
{
* Election years
gen year = 2002 in 1
replace year = 2005 in 2
replace year = 2009 in 3
replace year = 2013 in 4

* Initialize variables
gen SPD = .
gen Liberal = .
gen CDU = .
gen Total_Switching = .

* Election dates and party codes
local dates "22sep2002 18sep2005 27sep2009 22sep2013"
local SPD 41320
local Liberal 41420
local CDU 41521

* Loop over each date
local i = 1
foreach date of local dates {
    * Total Switching for the date
    quietly summarize switch_main if country == 41 & edate == date("`date'", "DMY")
    replace Total_Switching = r(mean) * 100 in `i'

    * SPD
    quietly summarize switch_main if country == 41 & edate == date("`date'", "DMY") & party_last == `SPD'
    replace SPD = r(mean) * 100 in `i'

    * Liberal
    quietly summarize switch_main if country == 41 & edate == date("`date'", "DMY") & party_last == `Liberal'
    replace Liberal = r(mean) * 100 in `i'

    * CDU
    quietly summarize switch_main if country == 41 & edate == date("`date'", "DMY") & party_last == `CDU'
    replace CDU = r(mean) * 100 in `i'

    local i = `i' + 1
}
}
// table A10: Switching in Germany from mainstream to non-mainstream parties 2002-2009
{
* Format the variables to display one decimal place
format SPD Liberal CDU Total_Switching %4.1f


* Use tabdisp to display the results in a tabular format
tabdisp year, c(SPD Liberal CDU Total_Switching)
}